package com.dofast.bt.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.dofast.bt.base.BaseApplication;

public class SpfUtil {
	private static final String DEFAULT_NAME = "kshili_cache";

	private static SpfUtil sInstance = null;
	private SharedPreferences spf = null;

	private SpfUtil() {
		spf = BaseApplication.getInstance().getSharedPreferences(DEFAULT_NAME, Context.MODE_APPEND);
	}

	public synchronized static SpfUtil getInstance() {
		if (sInstance == null) {
			sInstance = new SpfUtil();
		}
		return sInstance;
	}

	public void put(String key, String value) {
		Editor editor = spf.edit();
		editor.putString(key, value);
		editor.commit();
	}

	public String get(String key, String defValue) {
		return spf.getString(key, defValue);
	}

	public String get(String key){
		return get(key, null);
	}

	public void remove(String key){
		Editor editor = spf.edit();
		editor.remove(key);
		editor.commit();
	}

	public void clear(){
		Editor editor = spf.edit();
		editor.clear();
		editor.commit();
	}
}
